package com.example.aijie.autoreadhelper.appbean;

import android.annotation.TargetApi;

import com.example.aijie.autoreadhelper.constant.AppConstant;

import org.litepal.crud.LitePalSupport;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import cn.bmob.v3.BmobObject;

public class BaseAppBean extends LitePalSupport implements Serializable {
    private int enableToday;  // 是否可用  0--可以   其他-不可用  默认可用
    private String appName;  // app 名称
    private String packageName;  // 包名
    private String startClassName;  // 启动页的类名称
    private int articleReadTime = AppConstant.PER_ARTICLE_READ_SECOND;
    private List<String> newsDetailActivity; // 新闻详情页面
    private List<String> advPage; // 广告页面
    private String showAllBtnId; // 查看全部的按钮id
    private String homeActivity;  // 列表首页
    private int itemHeight;  // 条目高度

    // 需要有默认构造函数，litepal操作数据库需要用到，不可删除
    public BaseAppBean() {
    }

    public BaseAppBean(String appName, String packageName, String className) {
        this.appName = appName;
        this.packageName = packageName;
        this.startClassName = className;
        this.newsDetailActivity = new ArrayList<>();
    }

    public long getAppId(){
        return getBaseObjId();
    }

    public void addAdvPage(String pageStr) {
        if (advPage == null) {
            advPage = new ArrayList<>();
        }
        advPage.add(pageStr);
    }

    /**
     * 设置当天是否可用可用
     */
    public void setEnableToday(boolean enable) {
        enableToday = enable ? 0 : 1;
    }

    public boolean isEnable() {
        return enableToday == 0;
    }

    public List<String> getAdvPage() {
        return advPage;
    }

    public int getArticleReadTime() {
        return articleReadTime;
    }

    public int getItemHeight() {
        return itemHeight;
    }

    public void setItemHeight(int itemHeight) {
        this.itemHeight = itemHeight;
    }

    public List<String> getNewsDetailActivity() {
        if (newsDetailActivity == null) {
            newsDetailActivity = new ArrayList<>();
        }
        return newsDetailActivity;
    }

    public void addNewsDetailActivity(String detailActivity) {
        if (newsDetailActivity == null) {
            newsDetailActivity = new ArrayList<>();
        }
        this.newsDetailActivity.add(detailActivity);
    }

    public String getHomeActivity() {
        return homeActivity;
    }

    public void setHomeActivity(String homeActivity) {
        this.homeActivity = homeActivity;
    }

    public void setAdvPage(List<String> advPage) {
        this.advPage = advPage;
    }

    public void setArticleReadTime(int articleReadTime) {
        this.articleReadTime = articleReadTime;
    }

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public String getStartClassName() {
        return startClassName;
    }

    public void setClassName(String className) {
        this.startClassName = className;
    }

    public String getShowAllBtnId() {
        return showAllBtnId;
    }

    public void setShowAllBtnId(String showAllBtnId) {
        this.showAllBtnId = showAllBtnId;
    }

    @TargetApi(19)
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BaseAppBean appBean = (BaseAppBean) o;
        return Objects.equals(packageName, appBean.packageName) &&
                Objects.equals(startClassName, appBean.startClassName);
    }

    @TargetApi(19)
    @Override
    public int hashCode() {
        return Objects.hash(packageName, startClassName);
    }
}
